home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / createmsgport.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: createmsgport.c,v 1.3 1996/08/01 17:41:08 digulla Exp $
  4.     $Log: createmsgport.c,v $
  5.     Revision 1.3  1996/08/01 17:41:08  digulla
  6.     Added standard header for all files
  7.  
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include <exec/memory.h>
  12. #include <exec/ports.h>
  13. #include <exec/execbase.h>
  14. #include <aros/libcall.h>
  15.  
  16. /*****************************************************************************
  17.  
  18.     NAME */
  19.     #include <clib/exec_protos.h>
  20.  
  21.     __AROS_LH0(struct MsgPort *, CreateMsgPort,
  22.  
  23. /*  SYNOPSIS */
  24.  
  25. /*  LOCATION */
  26.     struct ExecBase *, SysBase, 111, Exec)
  27.  
  28. /*  FUNCTION
  29.     Create a new message port. A signal will be allocated and the message
  30.     port set to signal you task
  31.  
  32.     INPUTS
  33.  
  34.     RESULT
  35.     Pointer to messageport structure
  36.  
  37.     NOTES
  38.  
  39.     EXAMPLE
  40.  
  41.     BUGS
  42.  
  43.     SEE ALSO
  44.  
  45.     INTERNALS
  46.  
  47.     HISTORY
  48.  
  49. ******************************************************************************/
  50. {
  51.     __AROS_FUNC_INIT
  52.  
  53.     struct MsgPort *ret;
  54.  
  55.     /* Allocate memory for struct MsgPort */
  56.     ret=(struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC|MEMF_CLEAR);
  57.     if(ret!=NULL)
  58.     {
  59.     BYTE sb;
  60.  
  61.     /* Allocate a signal bit */
  62.     sb=AllocSignal(-1);
  63.     if(sb!=-1)
  64.     {
  65.         /* Initialize messageport structure. First set signal bit. */
  66.         ret->mp_SigBit=sb;
  67.  
  68.         /* Clear the list of messages */
  69.         ret->mp_MsgList.lh_Head=(struct Node *)&ret->mp_MsgList.lh_Tail;
  70.         /* ret->mp_MsgList.lh_Tail=NULL; */
  71.         ret->mp_MsgList.lh_TailPred=(struct Node *)&ret->mp_MsgList.lh_Head;
  72.  
  73.         /* Set port to type 'signalling' */
  74.         ret->mp_Flags=PA_SIGNAL;
  75.  
  76.         /* Finally set task to send the signal to. */
  77.         ret->mp_SigTask=SysBase->ThisTask;
  78.  
  79.         /* Now the port is ready for use. */
  80.         return ret;
  81.     }
  82.     /* Couldn't get the signal bit. Free the memory. */
  83.     FreeMem(ret,sizeof(struct MsgPort));
  84.     }
  85.     /* function failed */
  86.     return NULL;
  87.     __AROS_FUNC_EXIT
  88. } /* CreateMsgPort */
  89.  
  90.